from interface.MemberInterface import MemberInterface
from utils.SendMethod import SendMethod


class OrderInterface:
    def __init__(self, url, headers):
        self.url = url
        self.heders = headers

    # 确认订单
    def confirm_order(self, cart_id):
        method = "post"
        url = self.url + "/order/generateConfirmOrder"
        payload = [cart_id]
        return SendMethod.sendmethod(method=method, url=url, json=payload, headers=self.heders)

    # 根据购物车信息生成订单
    def generate_order(self, cart_id):
        method = "post"
        url = self.url + "/order/generateOrder"
        payload = {
            "cartIds": [cart_id],
            "memberReceiveAddressId": 2411,  # 收货地址
            "payType": 1  # 支付方式:0:未支付 1:支付宝 2:微信
        }
        return SendMethod.sendmethod(method=method, url=url, json=payload, headers=self.heders)

    # 用户支付成功的回调
    def user_paySuccess(self, orderId):
        method = "post"
        url = self.url + "/order/paySuccess"
        payload = {
            "orderId": orderId,
            "payType": 1
        }
        return SendMethod.sendmethod(method=method, url=url, data=payload, headers=self.heders)


if __name__ == '__main__':
    url = "http://47.108.206.100:8085"
    headers = MemberInterface(url).get_member_token("Anna", "anna123")
    Order = OrderInterface(url, headers)

    # print(Order.confirm_order(2723))
    # print(Order.generate_order(2723))
    print(Order.user_paySuccess(3481))





